import matplotlib.pyplot as plt
from wordcloud import WordCloud

# 关键词及其权重（比例）
keywords = {
    "低脂": 10, "高蛋白": 12, "低糖": 8, "低卡": 7, "无添加": 6,
    "瘦身": 8, "代餐": 9, "抗氧化": 5, "营养均衡": 6,
    "膳食纤维": 7, "维生素": 6, "酥脆": 5, "果仁": 4, "燕麦": 7,
    "网红推荐": 5, "健身人士": 7, "即食": 4, "健康": 9, "价格": 8,
    "味道": 8, "口感": 10, "包装": 6, "自然": 6, "美味": 7,
    "能量棒": 5, "轻食": 6, "低热量": 8, "纯天然": 5, "植物蛋白": 7,
    "蛋白棒": 6, "无麸质": 4, "无乳糖": 3, "零添加": 6, "低胆固醇": 5,
    "消化": 6, "耐饱": 5, "低升糖": 7, "无防腐剂": 4, "无人工色素": 4,
    "富含纤维": 5, "肠道健康": 6, "轻断食": 5, "有机": 7, "素食": 6,
    "儿童零食": 4, "运动补给": 6, "健身食品": 7, "脂肪燃烧": 5, "均衡饮食": 6,
    "高膳食纤维": 5, "饱腹感": 7, "全天然": 6, "能量补充": 5, "矿物质": 4,
    "无糖": 7, "无油炸": 5, "健康生活": 6, "清真": 4, "低GI": 5,
    "超级食物": 6, "维生素B群": 4, "高钙": 5, "助消化": 5, "美容养颜": 6,
    "健身达人": 5, "全天然配方": 4, "乳糖不耐": 3, "无味精": 4, "低钠": 5,
    "增强免疫": 6, "抗衰老": 5, "绿色食品": 6, "高纤维": 5, "低负担": 6,
    "轻量化饮食": 5, "膳食补充": 6, "高营养": 6, "运动能量": 5, "肠道护理": 6,
    "肌肉恢复": 5, "蛋白补充": 6, "益生菌": 4, "消化舒适": 5, "植物基": 6,
    "低碳水": 7, "心血管健康": 5, "抗炎": 4, "均衡营养": 6, "全天然零食": 5,
    "健康代餐": 6, "高铁": 4, "零食新选择": 5, "健康习惯": 6, "健身零食": 5,
    "好": 15, "产品": 10, "吃": 9, "质量": 12, "购物": 8, "收到": 7,
    "感觉": 10, "不错": 12, "比价": 6, "长": 5, "葡萄": 4, "物流": 9,
    "包装": 6, "配料表": 6, "速度": 6, "适合": 5
    }

# 生成词云图
wordcloud = WordCloud(
    font_path="simhei.ttf", 
    background_color="white", 
    width=800, 
    height=400,
    max_words=250,  # 增加最大词数
    relative_scaling=0.5,  # 调整词的相对大小比例
    collocations=False  # 避免自动组合词，增强紧密度
)
wordcloud.generate_from_frequencies(keywords)

# 显示词云图
plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()
